package br.org.acessobrasil.portal.persistencia;

import java.sql.Connection;
import java.sql.SQLException;
import java.util.Date;
import java.util.HashMap;
import java.util.List;

import javax.servlet.http.HttpSession;

import org.apache.log4j.Logger;

import br.org.acessobrasil.portal.modelo.ItemConteudo;
import br.org.acessobrasil.portal.modelo.Pagina;

/**
 * Utilizado para gravar temporariamente em sessao
 * @author Fabio Issamu Oshiro
 *
 */
public class ItemConteudoDaoTemp implements ItemConteudoDao {
	private static Logger logger = Logger.getLogger(ItemConteudoDaoTemp.class);
	private HashMap<Long, ItemConteudo> tabela = new HashMap<Long, ItemConteudo>();
	private HttpSession session;
	private static final String TABELA = "DaoTabela";

	@SuppressWarnings("unchecked")
	public ItemConteudoDaoTemp(HttpSession session) {
		this.session = session;
		if (session.getAttribute(TABELA) != null) {
			tabela = (HashMap<Long, ItemConteudo>) session.getAttribute(TABELA);
		}
	}

	
	public void apagar(ItemConteudo itemConteudo) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
		tabela.remove(itemConteudo.getNuItemConteudo());
		session.setAttribute(TABELA, tabela);
	}

	
	public void create(ItemConteudo itemConteudo) throws Exception {
		if (tabela == null) {
			tabela = new HashMap<Long, ItemConteudo>();
		}
		if (itemConteudo == null) {
			logger.error("Erro: itemConteudo = null");
		}
		tabela.put(itemConteudo.getNuItemConteudo(), itemConteudo);
		session.setAttribute(TABELA, tabela);
	}

	
	public ItemConteudo getItemConteudo(Long nu_item_conteudo) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
		return tabela.get(nu_item_conteudo);
	}

	
	public List<ItemConteudo> getListItemConteudo(long nu_conteudo, Connection con) throws SQLException {
		return null;
	}

	
	public void update(ItemConteudo itemConteudo) throws InstantiationException, IllegalAccessException, ClassNotFoundException, SQLException {
		try {
			this.apagar(itemConteudo);
			this.create(itemConteudo);
		} catch (Exception e) {
			e.printStackTrace();
		}
		session.setAttribute(TABELA, tabela);
	}

	
	public List<ItemConteudo> getListItemConteudoDescPublicado(long int1, Connection con) {
		return null;
	}

	
	public List<ItemConteudo> getListItemConteudoPublicado(long nu_conteudo, Connection con) throws SQLException {
		return null;
	}

	
	public List<ItemConteudo> getListItemConteudoDescPublicado(long int1, Connection con, Date dataIni, Date dataFim) {
		return null;
	}

	
	public List<ItemConteudo> getListItemConteudoPublicado(long nu_conteudo, Connection con, Date dataIni, Date dataFim) {
		return null;
	}

	
	public List<ItemConteudo> getListItemConteudoPublicado(Pagina pagina, int i) {
		return null;
	}

}
